//
//  NSString+MKSOFTSTR.m
//  正则表达式
//
//  Created by Burn on 2019/3/29.
//  Copyright © 2019 menksoft. All rights reserved.
//

#import "NSString+MKSOFTSTR.h"

@implementation NSString (MKSOFTSTR)

- (BOOL)isALLMKSOFTCODE{
    
    NSString *pattren1 = @"[a-zA-Z]";       //  拼音
    NSString *pattren2 = @"[\u4e00-\u9fa5]";    //  汉字
//    NSString *pattren3 = @"[\u1820-\u18aa\u202f]";   //  标准编码
//    NSString *pattrenSpace = @"[ ]";            //  空格
    
    NSError *error = nil;
    
    //  判断拼音
    NSRegularExpression *experssion = [NSRegularExpression regularExpressionWithPattern:pattren1 options:NSRegularExpressionCaseInsensitive error:&error];
    NSUInteger pinyin =  [experssion numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
    if (pinyin > 0 && error == nil) {
        return NO;
    }
    
    //  判断汉字
    NSRegularExpression *chinaExperssion = [NSRegularExpression regularExpressionWithPattern:pattren2 options:NSRegularExpressionCaseInsensitive error:&error];
    NSUInteger china =  [chinaExperssion numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
    if (china > 0 && error == nil) {
        return NO;
    }
    
    //  标准编码
//    NSRegularExpression *standardExperssion = [NSRegularExpression regularExpressionWithPattern:pattren3 options:NSRegularExpressionCaseInsensitive error:&error];
//    NSUInteger standard =  [standardExperssion numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
//    if (standard > 0 && error == nil) {
//        return NO;
//    }

    return YES;
    
}


- (BOOL)checkPwd{
    NSString *pattren1 = @"[a-z]";
    NSString *pattren2 = @"[0-9]";
    NSError *error = nil;
    
    NSRegularExpression *experssion = [NSRegularExpression regularExpressionWithPattern:pattren1 options:NSRegularExpressionCaseInsensitive error:&error];
    NSUInteger pinyin =  [experssion numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
    

    NSRegularExpression *experssion1 = [NSRegularExpression regularExpressionWithPattern:pattren2 options:NSRegularExpressionCaseInsensitive error:&error];
    NSUInteger number =  [experssion1 numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
    
    if (pinyin && number && error == nil) {
        return YES;
    }else{
        return NO;
    }
}


- (BOOL)checkName{
    NSError *error = nil;
    NSString *pattren2 = @"[\u4e00-\u9fa5]";    //  汉字
    //  判断汉字
    NSRegularExpression *chinaExperssion = [NSRegularExpression regularExpressionWithPattern:pattren2 options:NSRegularExpressionCaseInsensitive error:&error];
    NSUInteger china =  [chinaExperssion numberOfMatchesInString:self options:NSMatchingReportProgress range:NSMakeRange(0, self.length)];
    if (china > 0 && error == nil) {
        return NO;
    }else{
        return YES;
    }
    
}

@end
